package com.hxkj.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxkj.dao.ArticleDao;
import com.hxkj.dao.ColumnDao;
import com.hxkj.dao.ContentMappingDao;
import com.hxkj.domain.enums.ColumnExceptionEnum;
import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.Column;
import com.hxkj.domain.po.ColumnTree;
import com.hxkj.domain.po.ContentMapping;
import com.hxkj.service.ColumnService;
import com.hxkj.service.ContentMappingService;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.to.PageTo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ColumnServiceImpl
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/6/7 12:00
 * @Version 1.0
 */

@Service
@Slf4j
public class ColumnServiceImpl implements ColumnService {

    @Autowired
    private ColumnDao columnDao;
    @Autowired
    private ArticleDao articleDao;
    @Autowired
    private ContentMappingDao contentMappingDao;
    @Autowired
    private ContentMappingService contentMappingService;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Column saveColumn(Column column) throws Exception {
        try {
            //Mr.zheng:对比column名称是否已存在
            if (columnDao.getColumnByName(column.getColumnName(), column.getSiteId()).size() != 0) {
                throw new CustomException(ColumnExceptionEnum.COLUMN_IS_EXIST);
            }
            if (columnDao.getColumnByAlias(column.getAlias(),column.getSiteId()).size() != 0){
                throw new CustomMessageException(401,"该分类别名已存在");
            }
            List<ContentMapping> mappingList = column.getContentMappingList();
            Map<String, String> map = new HashMap<>();
            for (ContentMapping contentMapping : mappingList) {
                String str = contentMapping.getCustomName();
                if (map.containsKey(str)) {
                    throw new CustomMessageException(401, "扩展字段名不能重复！请重新填写！");
                }
            }

            // hzy:判断上级分类是否包含文章 ---一级的parentId为-1
            if (null != column.getParentColumnId() && column.getParentColumnId().longValue() != -1) {
                Article article = new Article();
                article.setColumnId(column.getParentColumnId());
                article.setSiteId(column.getSiteId());
                if (articleDao.getArticleByColumnId(article).size() > 0) {
                    throw new CustomException(ColumnExceptionEnum.COLUMN_SAVE_ERROR_BY_ARTICLE_EXIST);
                }

            }

            column = updateContentStatus(column, mappingList);

            int i = columnDao.saveColumn(column);

            if (i > 0 && mappingList != null && mappingList.size() > 0) {
                List<String> list = contentMappingService.getContentNameList().getData();//获取内容表的字段名
                for (int j = 0; j < mappingList.size(); j++) {
                    ContentMapping contentMapping = mappingList.get(j);
                    String contentName = list.get(j);
                    contentMapping.setContentName(contentName);//自动映射字段名称
                    contentMapping.setColumnId(column.getColumnId());
                    contentMappingDao.saveContentMapping(contentMapping);
                }
            }
            column.setContentMappingList(mappingList);


            // 同步保存至redis中
            redisTemplate.boundValueOps("column_" + column.getSiteId() + "_" + column.getColumnId()).set(column);
            // 清空redis中保存面包屑
            redisTemplate.delete("breadCrumbs_" + column.getSiteId() + "_" + column.getColumnId());

            return column;
        } catch (Exception e) {
            log.error("保存分类出错",e);
            throw new CustomException(ColumnExceptionEnum.COLUMN_SAVE_ERROE);
        }
    }

    @Override
    public List<ColumnTree> getColumnTreeList(Column column) throws Exception {
        List<ColumnTree> columnTreeList = new ArrayList<>();
        try {
            //Mr.zheng:递归调用获取文章分类的树结构
            columnTreeList = initTree(-1, column);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取文章分类失败");
        }
        return columnTreeList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeColumn(Column column) throws Exception {
        try {
            String[] columnIds = column.getColumnIds().split(",");
            for (int i = 0; i < columnIds.length; i++) {
                Long columnId = Long.valueOf(columnIds[i]);
                //Mr.zheng:确认该文章分类是否为父ID或有文章关联该分类
                affirmDeleteColumnByColumnId(columnId, column.getSiteId());
                columnDao.removeColumnById(columnId);

                ContentMapping contentMapping = new ContentMapping();
                contentMapping.setColumnId(columnId);
                contentMappingDao.removeByColumnId(contentMapping);//删除分类映射

                // 同步删除redis中保存的column
                redisTemplate.delete("column_" + column.getSiteId() + "_" + columnId);
                redisTemplate.delete("breadCrumbs" + column.getSiteId() + "_" + columnId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException(ColumnExceptionEnum.COLUMN_DELETE_ERROE);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void modifyColumn(Column column) throws Exception {
        try {
            List<ContentMapping> mappingList = column.getContentMappingList();
            ContentMapping contentMapping = new ContentMapping();
            contentMapping.setColumnId(column.getColumnId());
            Column col = columnDao.getColumnById(column.getColumnId());
            //Mr.zheng:查看分类名称和分类别名是否修改
            if (col.getColumnName().equals(column.getColumnName()) && (col.getAlias()==null? "":col.getAlias()).equals(column.getAlias())) {
                updateColumn(column, mappingList, contentMapping);
                return;
            }

            if (!col.getColumnName().equals(column.getColumnName()) && (col.getAlias()==null? "":col.getAlias()).equals(column.getAlias())) {
                //Mr.zheng:查看该分类名称是否重复
                if (columnDao.getColumnByName(column.getColumnName(), column.getSiteId()).size() == 0) {
                    updateColumn(column, mappingList, contentMapping);
                    return;
                }
            }
            if (col.getColumnName().equals(column.getColumnName()) && !(col.getAlias()==null? "":col.getAlias()).equals(column.getAlias())) {
                //Mr.zheng:查看该分类别名是否重复
                if (columnDao.getColumnByAlias(column.getAlias(),column.getSiteId()).size() == 0) {
                    updateColumn(column,  mappingList, contentMapping);
                    return;
                }
            }
            if (!col.getColumnName().equals(column.getColumnName()) && !(col.getAlias()==null? "":col.getAlias()).equals(column.getAlias())) {
                //Mr.zheng:查看该分类别名和分类名称是否重复
                if (columnDao.getColumnByAlias(column.getAlias(),column.getSiteId()).size() == 0 && columnDao.getColumnByName(column.getColumnName(), column.getSiteId()).size() == 0) {
                    updateColumn(column,  mappingList, contentMapping);
                    return;
                }
            }
            throw new CustomException(ColumnExceptionEnum.COLUMN_IS_EXIST);
        } catch (CustomException | CustomMessageException e){
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException(ColumnExceptionEnum.COLUMN_UPDATE_ERROE);
        }
    }

    private void updateColumn(Column column, List<ContentMapping> mappingList, ContentMapping contentMapping) throws Exception {
        column = updateContentStatus(column, mappingList);
        int i = columnDao.modifyColumn(column);
        //Mr.zheng:操作映射表
        if (i > 0) {
            //修改子类状态
            updateFunctionStatus(column.getColumnId(), column.getColumnStatus(), column.getSiteId());
            //修改扩展自定义字段
            updateContentMapping(mappingList, contentMapping, column);
        }
        redisTemplate.boundValueOps("column_" + column.getSiteId() + "_" + column.getColumnId()).set(column);
        // 删除redis中保存的面包屑
        redisTemplate.delete("breadCrumbs_" + column.getSiteId() + "_" + column.getColumnId());
    }

    private void updateContentMapping(List<ContentMapping> mappingList, ContentMapping contentMapping, Column column) throws Exception {
        List<ContentMapping> contentMappings = contentMappingDao.getContentMappingList(contentMapping);
        List<ContentMapping> contentMaps = new ArrayList<>();
        contentMaps.addAll(contentMappings);
        //获取内容表的字段名
        List<String> list = contentMappingService.getContentNameList().getData();
        for (ContentMapping contentMapping1 : contentMappings) {
            if (StringUtils.isNotBlank(contentMapping1.getContentName())) {
                //去除已被使用的字段
                list.remove(contentMapping1.getContentName());
            }
        }
        //Mr.zheng:对比自定义字段属性是否有删除或添加
        int count = 0;//定义一个计数索引
        for (int j = 0; j < mappingList.size(); j++) {
            ContentMapping contentMapp = mappingList.get(j);
            //id为空则为新增字段属性
            if (contentMapp.getId() != null) {
                for (ContentMapping contentMap : contentMappings) {
                    if (contentMap.getId() == contentMapp.getId()) {
                        contentMappingDao.update(contentMapp);
                        contentMaps.remove(contentMap);
                    }
                }
            } else {
                String contentName = list.get(count++);
                contentMapp.setColumnId(column.getColumnId());
                //自动映射字段名称
                contentMapp.setContentName(contentName);
                contentMappingDao.saveContentMapping(contentMapp);
            }
        }
        //Mr.zheng:如果大于0则代表有删除的字段
        if (contentMaps.size() > 0) {
            for (ContentMapping mapping : contentMaps) {
                //删除字段前先清空该字段下的所有内容
                contentMappingDao.removeContentByContentName(mapping);
                //删除自定义的字段
                contentMappingDao.removeById(mapping);
            }
        }
    }

    private Column updateContentStatus(Column column, List<ContentMapping> mappingList) {
        if (mappingList != null && mappingList.size() > 0) {
            column.setContentStatus(1);//有映射内容
        } else {
            column.setContentStatus(0);//没有映射内容
            //Mr.zheng:删除分类下所有文章的扩展内容
            columnDao.removeContentByColumnId(column.getColumnId());
        }
        return column;
    }

    public void updateFunctionStatus(Long columnId, long columnStatus, long siteId) {
        Column column = new Column();
        column.setParentColumnId(columnId);
        column.setSiteId(siteId);
        // 根据id来查询父节点是否有他
        List<Column> list = columnDao.getColumnList(column);
        if (null == list || list.size() < 1) {
            return;
        }
        for (Column col : list) {
            col.setColumnStatus(columnStatus);
            columnDao.modifyColumn(col);

            redisTemplate.boundValueOps("column_" + col.getSiteId() + "_" + col.getColumnId()).set(col);

            updateFunctionStatus(col.getColumnId(), columnStatus, col.getSiteId());
        }
    }

    @Override
    public ResultMessageStruct modifySortNum(Map<String, Object> map) throws Exception {
        ResultMessageStruct resultMessageStruct = new ResultMessageStruct();
        Column column = new Column();
        String[] id = map.get("ids").toString().split(",");
        column.setSiteId(Long.parseLong(map.get("siteId").toString()));
        for (int i = 0; i < id.length; i++) {
            try {
                column.setColumnId(Long.parseLong(id[i]));
                column.setSortNumber((long) i);
                int j = columnDao.modifySortNum(column);
                if (j == 1) {
                    resultMessageStruct.setCode(200);
                }
            } catch (Exception e) {
                e.printStackTrace();
                resultMessageStruct.setCode(ColumnExceptionEnum.COLUMN_SORT_NUM_ERROE.getCode());
                resultMessageStruct.setMessage(ColumnExceptionEnum.COLUMN_SORT_NUM_ERROE.getMsg());
                throw e;
            }

        }

        return resultMessageStruct;
    }

    @Override
    public PageInfo getColumnArticleList(Column column, PageTo pageTo) throws Exception {
        Page<Article> page = PageHelper.startPage(pageTo.getPageNum(), pageTo.getPageSize());
        PageInfo<Article> pageInfo = new PageInfo<>();
        List<Article> articleList;
        try {
            Article article = new Article();
            article.setSiteId(column.getSiteId());
            article.setColumnId(column.getColumnId());
            articleList = articleDao.getColumnArticleList(article);
            pageInfo = new PageInfo<>(page);
            pageInfo.setList(articleList);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取分类列表失败");
        }
        return pageInfo;
    }

    @Override
    public List<ColumnTree> getShowColumnTreeList(Column column) throws Exception {
        List<ColumnTree> columnTreeList = new ArrayList<>();
        try {
            //Mr.zheng:递归调用获取文章分类的树结构
            columnTreeList = initShowTree(-1, column);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取文章分类失败");
        }
        return columnTreeList;
    }


    //Mr.zheng:确认该文章分类是否为父ID或有文章关联该分类
    private void affirmDeleteColumnByColumnId(Long columnId, Long siteId) throws Exception {
        //Mr.zheng:如果文章分类为父节点则无法删除
        if (columnDao.getColumnByParentColumnId(columnId).size() != 0) {
            throw new CustomException(ColumnExceptionEnum.COLUMN_NOT_DELETE_BY_PARENT);
        }
        //Mr.zheng:如果文章分类有关联文章则无法删除
        Article article = new Article();
        article.setColumnId(columnId);
        article.setSiteId(siteId);
        if (articleDao.getArticleByColumnId(article).size() != 0) {
            throw new CustomException(ColumnExceptionEnum.COLUMN_NOT_DELETE_BY_ARTICLE);
        }
    }

    //Mr.zheng:递归调用获取文章分类的树结构
    private List<ColumnTree> initTree(long id, Column col) throws Exception {
        List<ColumnTree> columnTreeList = new ArrayList<>();
        Column column = new Column();
        column.setParentColumnId(id);
        column.setSiteId(col.getSiteId());
        List<Column> columnList = columnDao.getColumnList(column);
        if (columnList != null && columnList.size() != 0) {
            for (Column auf : columnList) {
                int contentStatus = auf.getContentStatus();
                //判断是否有映射字段并封装
                auf = addContentMappingList(auf, contentStatus);

                ColumnTree columnTree = new ColumnTree();
                //封装
                setColTree(auf, columnTree);
                //Mr.zheng:递归调用
                columnTree.setChildren(initTree(auf.getColumnId(), auf));

                columnTreeList.add(columnTree);
            }
        }
        return columnTreeList;
    }

    private Column addContentMappingList(Column auf, int contentStatus) {
        //判断是否有映射字段
        if (contentStatus == 1) {
            ContentMapping contentMapping = new ContentMapping();
            contentMapping.setColumnId(auf.getColumnId());
            List<ContentMapping> contentMappingList = contentMappingDao.getContentMappingList(contentMapping);
            auf.setContentMappingList(contentMappingList);
        }
        return auf;
    }

    //Mr.zheng:文章分类下拉框列表递归，状态为显示的
    private List<ColumnTree> initShowTree(long id, Column col) throws Exception {
        List<ColumnTree> columnTreeList = new ArrayList<>();
        Column column = new Column();
        column.setParentColumnId(id);
        column.setSiteId(col.getSiteId());
        List<Column> columnList = columnDao.getShowColumnList(column);
        if (columnList != null && columnList.size() != 0) {
            for (Column auf : columnList) {
                int contentStatus = auf.getContentStatus();
                auf = addContentMappingList(auf, contentStatus);

                ColumnTree columnTree = new ColumnTree();
                //封装
                setColTree(auf, columnTree);
                //Mr.zheng:递归调用
                columnTree.setChildren(initShowTree(auf.getColumnId(), auf));
                columnTreeList.add(columnTree);
            }
        }
        return columnTreeList;
    }

    @Override
    public List<Column> getChildren(Column column) throws Exception {

        Column col = new Column();
        col.setSiteId(column.getSiteId());
        col.setParentColumnId(column.getColumnId());
        List<Column> columnList = new ArrayList<>();
        try {
            columnList = columnDao.getShowColumnList(col);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取文章分类失败");
        }
        return columnList;
    }

    @Override
    public Column getColumn(Column column) throws Exception {
        try {
            Column column1;
            column1 = columnDao.getColumnById(column.getColumnId());
            return column1;
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取一条文章分类错误");
            throw e;
        }
    }

    @Override
    public List<ColumnTree> getColumnTreeListByKeyword(Column column) throws Exception {
        List<ColumnTree> columnTreeList = new ArrayList<>();
        try {
            List<Column> columnList = columnDao.getColumnList(column);
            for (Column col : columnList) {


                ColumnTree columnTree;
                int count = 0;//Mr.zheng:定义控制器，判断是否添加了重复的父节点
                if (col.getParentColumnId() != -1) {
                    //Mr.zheng:递归调用获取顶级父节点ID
                    Column co = getColumnByParentId(col.getParentColumnId());
                    int contentStatus = co.getContentStatus();
                    co = addContentMappingList(col, contentStatus);
                    //Mr.zheng:根据顶级父节点ID封装
                    columnTree = addParentColumn(co);

                    for (ColumnTree columnTree1 : columnTreeList) {
                        if (columnTree1.getColumnId() == columnTree.getColumnId()) {
                            count++;
                            break;
                        }
                    }
                    if (count == 0) {
                        columnTreeList.add(columnTree);
                    }
                } else {
                    int contentStatus = col.getContentStatus();
                    col = addContentMappingList(col, contentStatus);
                    //Mr.zheng:根据顶级父节点ID封装
                    columnTree = addParentColumn(col);
                    for (ColumnTree columnTree1 : columnTreeList) {
                        if (columnTree1.getColumnId() == columnTree.getColumnId()) {
                            count++;
                            break;
                        }
                    }
                    if (count == 0) {
                        columnTreeList.add(columnTree);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取文章分类错误");
        }
        return columnTreeList;
    }

    @Override
    public List<Column> getColumnListByTerms(Column column) throws Exception {
        List<Column> columnList = new ArrayList<>();
        try {
            columnList = columnDao.getShowColumnList(column);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("获取文章分类错误");
        }
        return columnList;
    }


    private ColumnTree addParentColumn(Column co) throws Exception {
        ColumnTree columnTree = new ColumnTree();
        //封装
        setColTree(co, columnTree);
        //Mr.zheng:递归调用
        columnTree.setChildren(initTree(co.getColumnId(), co));
        return columnTree;
    }

    private void setColTree(Column co, ColumnTree columnTree) {
        columnTree.setColumnName(co.getColumnName() == null ? "" : co.getColumnName());
        columnTree.setColumnId(co.getColumnId());
        columnTree.setParentColumnId(co.getParentColumnId());
        columnTree.setSortNumber(co.getSortNumber());
        columnTree.setComment(co.getComment() == null ? "" : co.getComment());
        columnTree.setFileName1(co.getFileName1() == null ? "" : co.getFileName1());
        columnTree.setImgUrl(co.getImgUrl() == null ? "" : co.getImgUrl());
        columnTree.setTempletName1(co.getTempletName1() == null ? "" : co.getTempletName1());
        columnTree.setPath1(co.getPath1() == null ? "" : co.getPath1());
        columnTree.setFileName2(co.getFileName2() == null ? "" : co.getFileName2());
        columnTree.setTempletName2(co.getTempletName2() == null ? "" : co.getTempletName2());
        columnTree.setPath2(co.getPath2() == null ? "" : co.getPath2());
        columnTree.setSiteId(co.getSiteId());
        columnTree.setCreateTime(co.getCreateTime());
        columnTree.setUpdateTime(co.getUpdateTime());
        columnTree.setTempletId(co.getTempletId());
        columnTree.setTempId(co.getTempId());
        columnTree.setmFirstListTempletId(co.getmFirstListTempletId());
        columnTree.setmListTempletId(co.getmListTempletId());
        columnTree.setmDetailTempletId(co.getmDetailTempletId());
        columnTree.setColumnStatus(co.getColumnStatus());
        columnTree.setColumnType(co.getColumnType());
        columnTree.setSeoDepict(co.getSeoDepict());
        columnTree.setSeoHeadline(co.getSeoHeadline());
        columnTree.setSeoKeyword(co.getSeoKeyword());
        columnTree.setManuscriptPath(co.getManuscriptPath());
        columnTree.setPageNum(co.getPageNum());
        columnTree.setPageSize(co.getPageSize());
        columnTree.setContentStatus(co.getContentStatus());
        columnTree.setContentMappingList(co.getContentMappingList());
        columnTree.setAlias(co.getAlias() == null ? "" : co.getAlias());
    }


    //Mr.zheng:获取顶级父类
    private Column getColumnByParentId(long parentColumnId) throws Exception {
        Column co = columnDao.getColumnById(parentColumnId);
        if (co.getParentColumnId() != -1) {
            getColumnByParentId(co.getParentColumnId());
        }
        return co;
    }

    //chenfangzhou
    @Override
    public Column getColumnByName(Column column) {
        return columnDao.getColumnByName_(column);
    }


    /**
     * 获取面包屑    chenfangzhou
     * 每条面包屑都保存到redis中
     */
    @Override
    public List<Column> getTopParentColumn(Column column) throws Exception {
        if (redisTemplate.hasKey("breadCrumbs_" + column.getSiteId() + "_" + column.getColumnId())) {
            return (List<Column>) redisTemplate.boundValueOps("breadCrumbs_" + column.getSiteId() + "_" + column.getColumnId()).get();
        }
        List<Column> breadCrumbsList = getParentColumn(column.getColumnId(), new ArrayList<>());


        redisTemplate.boundValueOps("breadCrumbs_" + column.getSiteId() + "_" + column.getColumnId()).set(breadCrumbsList);
        return breadCrumbsList;
    }


    private List<Column> getParentColumn(Long columnId, List<Column> list) {
        Column newcolumn = new Column();
        Column column = columnDao.getColumnById(columnId);
        if (column == null) {
            log.info("请配置正确的分类,查询到的分类id为" + columnId + "不在该站点下!");
            return list;
        }
        newcolumn.setColumnId(column.getColumnId());
        newcolumn.setColumnName(column.getColumnName());
        newcolumn.setManuscriptPath(column.getManuscriptPath());
        list.add(newcolumn);
        if (column.getParentColumnId() != -1) {
            getParentColumn(column.getParentColumnId(), list);
        }
        return list;
    }


    public List<Column> getColumnList(Column column) throws Exception {
        try {
            return columnDao.getColumnList(column);
        } catch (Exception e) {
            log.error("分类查询出错",e);
            throw new CustomException(ColumnExceptionEnum.COLUMN_SEARCH_TAGS_NOT_EXIST);
        }
    }


    public List<Column> getAllColumnList(Column column) throws Exception {
        try {
            List<Column> columnList = new ArrayList<>();
            return this.initTree(column.getColumnId(), column, columnList);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException(ColumnExceptionEnum.COLUMN_SEARCH_TAGS_NOT_EXIST);
        }
    }


    private List<Column> initTree(long id, Column col, List<Column> columnList) throws Exception {
        Column column = new Column();
        column.setParentColumnId(id);
        column.setSiteId(col.getSiteId());
        List<Column> columnListData = columnDao.getColumnList(column);
        if (columnListData != null && columnListData.size() != 0) {
            for (Column auf : columnListData) {
                if (auf.getParentColumnId().equals(col.getColumnId())) {
                    initTree(auf.getColumnId(), auf, columnList);
                }
                columnList.add(auf);
            }
        }
        return columnList;
    }


    @Override
    public List<Column> getColumnListByTempletIds(Column column) throws Exception {
        return columnDao.getColumnListByTempletIds(column);
    }

    @Override
    public Column getColumnByTempletId(Column column) throws Exception {
        try {
            List<Column> columnList = columnDao.getColumnByTempletId(column);
            if (columnList != null && columnList.size() != 0) {
                return columnList.get(0);
            }
            throw  new CustomMessageException(401,"没有分类引用该模板");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public void modifyTemptId(Column column) throws Exception {
        // 删除redis之前存的值
        redisTemplate.delete("column_" + column.getSiteId() + "_" + column.getColumnId());
        int i = columnDao.modifyTemptId(column);
        redisTemplate.boundValueOps("column_" + column.getSiteId() + "_" + column.getColumnId()).set(column);
        if (i == 1) {
           return;
        }
        throw  new CustomMessageException(401,"修改模板ID失败");
    }
}
